//
//  TimelineCellBottomView.swift
//  01sinablog
//
//  Created by ZhangZiang on 15/12/18.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

class TimelineCellBottomView: UIView {

    @objc private func commentDidClicked() {
        
        let vc = TempViewController()
       
        //通过响应者链条传递方法
        navController()?.pushViewController(vc, animated: true)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI()
    {
        addSubview(retweet)
        addSubview(comment)
        addSubview(like)
        
        //设置约束(三等分)
        retweet.snp_makeConstraints { (make) -> Void in
            make.top.left.bottom.equalTo(self)
        }
        like.snp_makeConstraints { (make) -> Void in
            make.top.right.bottom.equalTo(self)
            make.width.equalTo(retweet)
        }
        comment.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(retweet)
            make.left.equalTo(retweet.snp_right)
            make.right.equalTo(like.snp_left)
            make.width.equalTo(retweet)
        }
        
        //加分割线
        let seplineLeft = sepline()
        let seplineRight = sepline()
        
        addSubview(seplineLeft)
        addSubview(seplineRight)
        
        let sepheightScale = 0.4
        let sepwidth = 0.5
        
        seplineLeft.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweet.snp_right)
            make.centerY.equalTo(retweet.snp_centerY)
            make.width.equalTo(sepwidth)
            make.height.equalTo(retweet.snp_height).multipliedBy(sepheightScale)
        }
        
        seplineRight.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(like.snp_left)
            make.centerY.equalTo(like.snp_centerY)
            make.width.equalTo(sepwidth)
            make.height.equalTo(like.snp_height).multipliedBy(sepheightScale)
        }
        
        //给按钮加事件
        comment.addTarget(self, action: "commentDidClicked", forControlEvents: .TouchUpInside)
    }
    

    
    private func sepline() -> UIView
    {
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }
    
    // MARK : 懒加载控件
    lazy var retweet = UIButton(title: "转发", backImageName: nil, color: UIColor.darkGrayColor(), fontSize: 10, imageName: "timeline_icon_retweet")
    lazy var comment = UIButton(title: "评论", backImageName: nil, color: UIColor.darkGrayColor(), fontSize: 10, imageName: "timeline_icon_comment")
    
    lazy var like = UIButton(title: "喜欢", backImageName: nil, color: UIColor.darkGrayColor(), fontSize: 10, imageName: "timeline_icon_unlike")
}
